package com.smart.lib.controller;

import com.smart.lib.entity.BookCategoryInfo;
import com.smart.lib.entity.BookInfo;
import com.smart.lib.entity.BorrowOrderInfo;
import com.smart.lib.service.BookCategoryService;
import com.smart.lib.service.BookService;
import com.smart.lib.service.BorrowService;
import com.smart.lib.util.Pager;
import com.smart.lib.util.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 图书管理相关API接口
 * */
@RestController
@CrossOrigin
@RequestMapping("/book")
public class BookController {
    @Autowired
    BookCategoryService bookCategoryService;
    @Autowired
    BookService bookService;
    @Autowired
    BorrowService borrowService;

    /**
     * 获取所有图书分类信息API
     * */
    @RequestMapping(value = "/getAllBookCategory", method = RequestMethod.GET, produces = "application/json; utf-8")
    public Response getAllBookCategory(){
        return bookCategoryService.getAllBookCategory();
    }

    /**
     * 添加图书分类API
     * */
    @RequestMapping(value = "/addBookCategory", method = RequestMethod.POST, produces = "application/json; utf-8")
    public Response addBookCategory(@RequestBody BookCategoryInfo bookCategoryInfo){
        return bookCategoryService.addBookCategory(bookCategoryInfo);
    }

    /**
     * 编辑图书分类API
     * */
    @RequestMapping(value = "/editBookCategory", method = RequestMethod.POST, produces = "application/json; utf-8")
    public Response editBookCategory(@RequestBody BookCategoryInfo bookCategoryInfo){
        return bookCategoryService.editBookCategory(bookCategoryInfo);
    }

    /**
     * 添加图书API
     * */
    @RequestMapping(value = "/addBook", method = RequestMethod.POST, produces = "application/json; utf-8")
    public Response addBook(@RequestBody BookInfo bookInfo){
        return bookService.addBook(bookInfo);
    }

    /**
     * 编辑图书信息API
     * */
    @RequestMapping(value = "/editBook", method = RequestMethod.POST, produces = "application/json; utf-8")
    public Response editBook(@RequestBody BookInfo bookInfo){
        return bookService.editBook(bookInfo);
    }

    /**
     * 查询图书信息分页数据+搜索 API
     * */
    @RequestMapping(value = "/getBookPagerDataBySearch",method = RequestMethod.POST,produces = "application/json; utf-8")
    public Response getBookPagerDataBySearch(@RequestBody Pager pager){
        return bookService.getBookPagerDataBySearch(pager);
    }

    /**
     * 图书借阅中通过ISBN码查询图书信息用于借阅和归还 API
     * */
    @RequestMapping(value = "/getBookInfoByISBN",method = RequestMethod.POST,produces = "application/json; utf-8")
    public Response getBookInfoByISBN(@RequestBody BookInfo bookInfo){
        return bookService.getBookInfoByISBN(bookInfo);
    }

    /**
     * 图书借阅流程
     * 借阅书籍API
     * */
    @RequestMapping(value = "/borrowBook",method = RequestMethod.POST,produces = "application/json; utf-8")
    public Response borrowBook(@RequestBody BorrowOrderInfo borrowOrderInfo){
        return borrowService.borrowBook(borrowOrderInfo);
    }

    /**
     * 图书借阅流程
     * 归还籍API
     * */
    @RequestMapping(value = "/returnBook",method = RequestMethod.POST,produces = "application/json; utf-8")
    public Response returnBook(@RequestBody BorrowOrderInfo borrowOrderInfo){
        return borrowService.returnBook(borrowOrderInfo);
    }

    /**
     * 根据查询获取图书订阅订单数据
     * */
    @RequestMapping(value = "/getBorrowOrderPagerData",method = RequestMethod.POST,produces = "application/json; utf-8")
    public Response getBorrowOrderPagerDataBySearch(@RequestBody Pager pager){
        return borrowService.getBorrowOrderPagerDataBySearch(pager);
    }
}
